﻿Public Class ClsHand
    'represents mouse action - what is user performing by mouse

#Region "Attributes"
#Region "Private attributes"
    Private MePrimaryOperation As GePrimaryOperationOfHand = GePrimaryOperationOfHand.kkNeutral 'primary action
    Private MeSecondaryOperation As GeSecondaryOperationOfHand = GeSecondaryOperationOfHand.kkIdle 'secondary action (zoom,...)
    Private MeTypeOfLink As kkRelationTypes = kkRelationTypes.kk_1_n 'GeTypeOfLink = GeTypeOfLink.kkLink1a01 'type of link for creating
    'semaphores
    Private MbIsChangingPrimaryOperation As Boolean = False 'primary action is changing
    Private MbIsChangingSecondaryOperation As Boolean = False 'secondary action is changing
    Private MbIsChangingTypeOfLink As Boolean = False 'type of link is changing
#End Region
#End Region
#Region "Events"
    Public Event OnChangePrimaryOperationOfHand(ByVal OldStatus As GePrimaryOperationOfHand) 'after primary action is changed
    Public Event OnChangeSecondaryOperationOfHand(ByVal OldStatus As GeSecondaryOperationOfHand) 'after secondary action is changed
    Public Event OnChangeTypeOfLink(ByVal OldTypeOfLink As kkRelationTypes) 'GeTypeOfLink) 'after type of link is changed
#End Region
#Region "Constructors"
    Sub New()
        MePrimaryOperation = GePrimaryOperationOfHand.kkNeutral
        MeSecondaryOperation = GeSecondaryOperationOfHand.kkIdle
        MbIsChangingPrimaryOperation = False
        MbIsChangingSecondaryOperation = False
    End Sub
#End Region
#Region "Properties"
#Region "Public properties"
    Public Property PrimaryOperation() As GePrimaryOperationOfHand
        Get
            Return MePrimaryOperation
        End Get
        Set(ByVal IeValue As GePrimaryOperationOfHand)
            If Not MbIsChangingPrimaryOperation Then 'change will be processed only if change is not processing right now
                MbIsChangingPrimaryOperation = True
                Dim LeOldOperation As GePrimaryOperationOfHand = MePrimaryOperation 'remember old operation
                MePrimaryOperation = IeValue 'set new operation
                RaiseEvent OnChangePrimaryOperationOfHand(LeOldOperation) 'fire event with parameter of old operation
                MbIsChangingPrimaryOperation = False
            End If
        End Set
    End Property
    Public Property SecondaryOperation() As GeSecondaryOperationOfHand
        Get
            Return MeSecondaryOperation
        End Get
        Set(ByVal IeValue As GeSecondaryOperationOfHand)
            If Not MbIsChangingSecondaryOperation Then 'change will be processed only if change is not processing right now
                MbIsChangingSecondaryOperation = True
                Dim LeOldOperation As GeSecondaryOperationOfHand = MeSecondaryOperation 'remember old operation
                MeSecondaryOperation = IeValue 'set new operation
                RaiseEvent OnChangeSecondaryOperationOfHand(LeOldOperation) 'fire event with parameter of old operation
                MbIsChangingSecondaryOperation = False
            End If
        End Set
    End Property
    Public Property TypeOfLink() As kkRelationTypes
        Get
            Return MeTypeOfLink
        End Get
        Set(ByVal IeValue As kkRelationTypes)
            If Not MbIsChangingTypeOfLink Then  'change will be processed only if change is not processing right now
                MbIsChangingTypeOfLink = True
                Dim LeOldTypeOfLink As kkRelationTypes = MeTypeOfLink 'GeTypeOfLink = MeTypeOfLink 'remember old type of link
                MeTypeOfLink = IeValue 'set new type of link
                RaiseEvent OnChangeTypeOfLink(LeOldTypeOfLink) 'fire event with parameter of old type of link
                MbIsChangingTypeOfLink = False
            End If
        End Set
    End Property
    Public ReadOnly Property IsChangingPrimaryOperation() As Boolean
        Get
            Return MbIsChangingPrimaryOperation
        End Get
    End Property
    Public ReadOnly Property IsChangingSecondaryOperation() As Boolean
        Get
            Return MbIsChangingSecondaryOperation
        End Get
    End Property
    Public ReadOnly Property IsChangingTypeOfLink() As Boolean
        Get
            Return MbIsChangingTypeOfLink
        End Get
    End Property
#End Region
#End Region

End Class
